Socket
Socket
Sign inDemoInstall

option-cache

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

option-cache

Simple API for managing options in JavaScript applications.


Version published
Weekly downloads
27K
increased by0.94%
Maintainers
1
Weekly downloads
 
Created
Source

option-cache NPM version Build Status

Simple API for managing options in JavaScript applications.

Install

Install with npm

$ npm i option-cache --save

Docs

(Table of contents generated by verb)

API

Options

Create a new instance of Options.

Params

  • options {Object}: Initialize with default options.

Example

var app = new Options();

.option

Set or get an option.

Params

  • key {String}: The option name.
  • value {*}: The value to set.
  • returns {*}: Returns a value when only key is defined.

Example

app.option('a', true);
app.option('a');
//=> true

.enable

Enable key.

Params

  • key {String}
  • returns {Object} Options: to enable chaining

Example

app.enable('a');

.disable

Disable key.

Params

  • key {String}: The option to disable.
  • returns {Object} Options: to enable chaining

Example

app.disable('a');

.enabled

Check if key is enabled (truthy).

Params

  • key {String}
  • returns {Boolean}

Example

app.enabled('a');
//=> false

app.enable('a');
app.enabled('a');
//=> true

.disabled

Check if key is disabled (falsey).

Params

  • key {String}
  • returns {Boolean}: Returns true if key is disabled.

Example

app.disabled('a');
//=> true

app.enable('a');
app.disabled('a');
//=> false

.isTrue

Returns true if the value of key is strictly true.

Params

  • key {String}
  • returns {Boolean}: Uses strict equality for comparison.

Example

app.option('a', 'b');
app.isTrue('a');
//=> false

app.option('c', true);
app.isTrue('c');
//=> true

.isFalse

Returns true if the value of key is strictly false.

Params

  • key {String}
  • returns {Boolean}: Uses strict equality for comparison.

Example

app.option('a', null);
app.isFalse('a');
//=> false

app.option('c', false);
app.isFalse('c');
//=> true

.isBoolean

Return true if the value of key is either true or false.

Params

  • key {String}
  • returns {Boolean}: True if true or false.

Example

app.option('a', 'b');
app.isBoolean('a');
//=> false

app.option('c', true);
app.isBoolean('c');
//=> true

.hasOption

Return true if options.hasOwnProperty(key)

Params

  • key {String}
  • returns {Boolean}: True if key is is on options.

Example

app.hasOption('a');
//=> false
app.option('a', 'b');
app.hasOption('a');
//=> true

.flags

Generate an array of command line args from the given keys or all options.

Params

  • keys {Array}
  • returns {Array}: Array of args

Example

// set some options
app.option('foo', 'bar');
app.option('abc', true);
app.option('xyz', 10);
app.option('one', false);

// create command line args for all options
app.flags();
//=> ['--foo=bar', '--abc', '--xyz=10', '--no-one']

// or specific options
app.flags(['foo', 'abc']);
//=> ['--foo=bar', '--abc']



Example app

Use options-cache in your javascript application:

var util = require('util');
var Options = require('options-cache');

function App(options) {
  Options.call(this, options);
  this.init();
}

util.inherits(App, Options);

App.prototype.init = function() {
  this.option('cwd', process.cwd());
  this.option('foo', 'bar');
};

App.prototype.a = function(value) {
  this.enable(value);
};

App.prototype.b = function(value) {
  if (this.enabled(value)) {
    // do something
  } else {
    // do something else
  }
};



  • cache-base: Generic object cache for node.js/javascript projects.
  • config-cache: General purpose JavaScript object storage methods.
  • engine-cache: express.js inspired template-engine manager.
  • helper-cache: Easily register and get helper functions to be passed to any template engine or node.js… more
  • loader-cache: Register loader functions that dynamically read, parse or otherwise transform file contents when the name… more
  • map-cache: Basic cache object for storing key-value pairs.
  • parser-cache: Cache and load parsers, similiar to consolidate.js engines.

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue

Running tests

Install dev dependencies:

$ npm i -d && npm test

Author

Jon Schlinkert

License

Copyright © 2015 Jon Schlinkert Released under the MIT license.


This file was generated by verb-cli on June 13, 2015.

Keywords

FAQs

Package last updated on 13 Jun 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc